﻿using PetaPoco;
using PmSoft;
using PmSoft.Caching;
using PmSoft.Entity;
using static Modules.Project.ProjectConstants;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using SqlSugar;

namespace Modules.System.User
{
    /// <summary>
    /// 主管用户表
    ///</summary>
    [TableName("sys_user")]
    [Description("主管用户表")]
    [PrimaryKey("user_id", AutoIncrement = true)]
    [CacheSetting(true, PropertyNamesOfArea = "DeptId")]
    [Serializable]
    public class SysUser : IDelEntity, IUser
    {
        /// <summary>
        ///  用户ID
        ///</summary>
        [Column("user_id")]
        public int UserId { get; set; }

        /// <summary>
        /// 身份证号码)
        ///</summary>
        [Column("cardno")]
        public string Cardno { get; set; }

        /// <summary>
        /// 姓名
        ///</summary>
        [Column("name")]
        public string Name { get; set; }

        /// <summary>
        /// 性别 1：男2：女
        ///</summary>
        [Column("gender")]
        public byte? Gender { get; set; }
        /// <summary>
        /// 归属省代码
        ///</summary>
        [Column("province_code")]
        public int? ProvinceCode { get; set; }

        /// <summary>
        /// 归属地市代码
        ///</summary>
        [Column("city_code")]
        public int? CityCode { get; set; }

        /// <summary>
        /// 归属区县代码
        ///</summary>
        [Column("area_code")]
        public int? AreaCode { get; set; }
        /// <summary>
        /// 手机号码
        ///</summary>
        [Column("mobile")]
        public string Mobile { get; set; }

        /// <summary>
        /// 电子邮箱
        ///</summary>
        [Column("email")]
        public string Email { get; set; }

        /// <summary>
        /// 归属部门ID
        ///</summary>
        [Column("dept_id")]
        public int? DeptId { get; set; }

        /// <summary>
        /// 安全信息ID
        ///</summary>
        [Column("security_id")]
        public int SecurityId { get; set; }

        /// <summary>
        /// 状态 1：正常，2:离岗,3：封禁
        ///</summary>
        [Column("status")]
        public byte Status { get; set; }

        /// <summary>
        /// 创建时间
        /// 默认值: CURRENT_TIMESTAMP
        ///</summary>
        [Column("create_time")]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 是否删除 0:否,1:是
        /// 默认值: b'0'
        ///</summary>
        [Column("is_deleted")]
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 是否系统保留，无法删除
        /// 默认值: b'0'
        ///</summary>
        [Column("is_keep")]
        public bool IsKeep { get; set; }

        /// <summary>
        /// 行业分类
        /// </summary>
        [Column("industry_type")]
        public 行业主管部门? IndustryType { get; set; }

        #region IEntity 成员

        [Ignore]
        object IEntity.EntityId { get { return UserId; } }

        [Ignore]
        bool IDelEntity.IsDeletedInDatabase { get => IsDeleted; set => IsDeleted = value; }

        #endregion IEntity 成员

        #region IUser

        [Ignore]
        string IUser.Name => Name;

        [Ignore]
        int IUser.Id => UserId;

        [Ignore]
        UserType IUser.Type => UserType.SysUser;

        #endregion IUser
    }

    /// <summary>
    /// 用户
    /// </summary>
    [SugarTable("sys_user")]
    public class SysUserSugar
    {
        /// <summary>
        /// 主键
        /// </summary>
        [SugarColumn(ColumnName = "user_id", IsPrimaryKey = true, IsIdentity = true)]
        public int UserId { get; set; }

        /// <summary>
        /// 身份证号码)
        ///</summary>
        [SugarColumn(ColumnName = "cardno")]
        public string Cardno { get; set; }

        /// <summary>
        /// 姓名
        ///</summary>
        [SugarColumn(ColumnName = "name")]
        public string Name { get; set; }

        /// <summary>
        /// 性别 1：男2：女
        ///</summary>
        [SugarColumn(ColumnName = "gender")]
        public byte? Gender { get; set; }
        /// <summary>
        /// 归属省代码
        ///</summary>
        [SugarColumn(ColumnName = "province_code")]
        public int? ProvinceCode { get; set; }

        /// <summary>
        /// 归属地市代码
        ///</summary>
        [SugarColumn(ColumnName = "city_code")]
        public int? CityCode { get; set; }

        /// <summary>
        /// 归属区县代码
        ///</summary>
        [SugarColumn(ColumnName = "area_code")]
        public int? AreaCode { get; set; }
        /// <summary>
        /// 手机号码
        ///</summary>
        [SugarColumn(ColumnName = "mobile")]
        public string Mobile { get; set; }

        /// <summary>
        /// 电子邮箱
        ///</summary>
        [SugarColumn(ColumnName = "email")]
        public string Email { get; set; }

        /// <summary>
        /// 归属部门ID
        ///</summary>
        [SugarColumn(ColumnName = "dept_id")]
        public int? DeptId { get; set; }

        /// <summary>
        /// 安全信息ID
        ///</summary>
        [SugarColumn(ColumnName = "security_id")]
        public int SecurityId { get; set; }

        /// <summary>
        /// 状态 1：正常，2:离岗,3：封禁
        ///</summary>
        [SugarColumn(ColumnName = "status")]
        public byte Status { get; set; }

        /// <summary>
        /// 创建时间
        /// 默认值: CURRENT_TIMESTAMP
        ///</summary>
        [SugarColumn(ColumnName = "create_time")]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 是否删除 0:否,1:是
        /// 默认值: b'0'
        ///</summary>
        [SugarColumn(ColumnName = "is_deleted")]
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 是否系统保留，无法删除
        /// 默认值: b'0'
        ///</summary>
        [SugarColumn(ColumnName = "is_keep")]
        public bool IsKeep { get; set; }

        /// <summary>
        /// 行业分类
        /// </summary>
        [SugarColumn(ColumnName = "industry_type")]
        public 行业主管部门? IndustryType { get; set; }
    }
}